﻿/*===============================================================
 TASK 7:                                                {Methods}
 Write a method that reverses the digits of given decimal number.
 Example: 256 => 652
 ===============================================================*/

using System;

class ReverseDigits
{
    static void Main()
    {
        Console.Write("Enter number:");
        int number = int.Parse(Console.ReadLine());

        //int number = 256;
        int rev = ReverseDig(number);

        Console.WriteLine(rev);
    }

    static int ReverseDig(int number)
    {
        int inputNumber=0;
        int digitForReverse = 0;
        int reversedNumber = 0;
        bool areMoreDigits = true;

        if (number < 0)
        {
            inputNumber = number;
            number*= -1;
        }
        while (areMoreDigits)
        {
            digitForReverse = number % 10;
            reversedNumber = reversedNumber * 10 + digitForReverse;
            if (number < 10)
            {
                areMoreDigits = false;
            }
            number = number / 10;
        }

        if (inputNumber < 0)
        {
            return reversedNumber * -1;
        }
        else
        {
            return reversedNumber;
        }
        
    }
}

